package com.kehongborui.empmanagesys.service;

import com.kehongborui.empmanagesys.entity.User;
import com.kehongborui.empmanagesys.mapper.UserMapper;
import com.kehongborui.empmanagesys.util.SqlSessionFactoryUtil;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

/**
 * @author zhang peng yang ming
 * @CopyRight (C) http://www.csdn.com
 * @brief
 * @email 122162005@qq.com
 * @date 2018-07-18
 */
public class LoginService {
    /**
     * 登录业务逻辑教研方法
     * @return
     */
    public boolean login(String username, String password) {
        // 获取用户
        SqlSessionFactory sqlSessionFactory = SqlSessionFactoryUtil.getSqlSessionFactory02();
        SqlSession session = sqlSessionFactory.openSession();
        UserMapper mapper = session.getMapper(UserMapper.class);
        User user = mapper.findByUsername(username);

        if (user == null) { // 用户不存在，返回false
            return false;
        } else { // 用户存在，则要判断密码是否一致，
            if (password.equals(user.getPassword())) {
                return true;
            }
            return false;
        }
    }

    /**
     * 退出登录
     * @return
     */
    public boolean logout() {
        return false;
    }
}
